home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-16 | 6.9 KB | 244 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Dialog.cpp
- // Release Version: $ ODF 3 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef DIALOG_H
- #include "Dialog.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- ODF Includes -----
-
- #ifndef FWEDVIEW_H
- #include "FWEdView.h"
- #endif
-
- #ifndef FWNOTIFN_H
- #include "FWNotifn.h"
- #endif
-
- #ifndef FWKEYF_H
- #include "FWKeyF.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- #ifndef SLMIXOS_H
- #include "SLMixOS.h" // for FW_Beep
- #endif
-
- #ifndef FWCLUSTR_H
- #include "FWClustr.h"
- #endif
-
- //========================================================================================
- // Segmentation
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdraw
- #endif
-
- //========================================================================================
- // Static methods
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // EnableDisableEditView
- //----------------------------------------------------------------------------------------
- // [HLX] Should be in the framework ??
-
- static void EnableDisableEditView(Environment* ev, FW_CEditView* view, FW_Boolean enable)
- {
- if (enable)
- {
- view->Enable(ev);
- view->SelectAll(ev);
- }
- else
- {
- view->SelectText(ev, 0, 0);
- view->Disable(ev);
- }
- }
-
- //========================================================================================
- // CRoundCornersDialogFrame class
- //========================================================================================
-
- FW_DEFINE_AUTO(CRoundCornersDialogFrame)
-
- //----------------------------------------------------------------------------------------
- // CRoundCornersDialogFrame constructor
- //----------------------------------------------------------------------------------------
-
- CRoundCornersDialogFrame::CRoundCornersDialogFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- CDrawPart* part) :
- FW_CDialogFrame(ev, odFrame, presentation, part),
- fDrawPart(part),
- fPointsView(NULL),
- fRoundEndsButton(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundCornersDialogFrame destructor
- //----------------------------------------------------------------------------------------
-
- CRoundCornersDialogFrame::~CRoundCornersDialogFrame()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundCornersDialogFrame::PostCreateViewFromStream
- //----------------------------------------------------------------------------------------
-
- void CRoundCornersDialogFrame::PostCreateViewFromStream(Environment* ev)
- {
- // ----- Call inherited to propagate to all subviews if necessary
- FW_CSuperView::PostCreateViewFromStream(ev);
-
- // ----- Find our views -----
- fPointsView = (FW_CEditView*)FindViewByID(ev, kPointsID);
- fRoundEndsButton = (FW_CButton*)FindViewByID(ev, kRoundEndsID);
- FW_CButton* radiusButton = (FW_CButton*)FindViewByID(ev, kRadiusID);
-
- // ----- Create a cluster -----
- FW_CRadioCluster* cluster = FW_NEW(FW_CRadioCluster, (ev));
- cluster->AddRadio(ev, fRoundEndsButton);
- cluster->AddRadio(ev, radiusButton);
-
- // ----- Initialize fields -----
- FW_CString initialString;
- initialString.ReplaceAllAsSignedDecimalInteger(FW_FixedToInt(fDrawPart->GetRoundRectRadius()));
- fPointsView->SetText(ev, initialString);
- fPointsView->SelectAll(ev);
-
- fPointsView->AdoptEventHandler(ev, FW_NEW(CNumberFilter, ()));
-
- fRoundEndsButton->SetValue(ev, fDrawPart->UseRoundEnds() ? 1 : 0);
- radiusButton->SetValue(ev, fDrawPart->UseRoundEnds() ? 0 : 1);
-
- EnableDisableEditView(ev, fPointsView, !fDrawPart->UseRoundEnds());
-
- // WARNING: Make sure that classes created from resources won't be dead-stripped
- FW_DO_NOT_DEAD_STRIP(FW_CButton);
- FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
- FW_DO_NOT_DEAD_STRIP(FW_CEditView);
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundCornersDialogFrame::HandleNotification
- //----------------------------------------------------------------------------------------
-
- void CRoundCornersDialogFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
- {
- FW_Message msg = notification.GetMessage();
-
- switch (msg)
- {
- case kRoundEndsPressedMsg:
- case kRadiusPressedMsg:
- EnableDisableEditView(ev, fPointsView, msg == kRadiusPressedMsg);
- break;
- case FW_kDefaultButtonMsg:
- {
- // ---- Get new settings from edit fields when clicking on Set button ----
- FW_CString str = fPointsView->GetText(ev);
- fDrawPart->ChangeRoundRectRadius(FW_IntToFixed(str.ParseAsSignedInteger()));
-
- fDrawPart->ChangeRoundEnds(fRoundEndsButton->GetValue(ev));
- }
- break;
- }
-
- // Must call inherited to close the dialog on OK & Cancel
- // WARNING: do not do anything else after this call... the dialog is gone!
- FW_CDialogFrame::HandleNotification(ev, notification);
- }
-
- //========================================================================================
- // CNumberFilter class
- //========================================================================================
-
- FW_DEFINE_AUTO(CNumberFilter)
- FW_DEFINE_CLASS_M1(CNumberFilter, FW_MEventHandler)
-
- //----------------------------------------------------------------------------------------
- // CNumberFilter constructor
- //----------------------------------------------------------------------------------------
- CNumberFilter::CNumberFilter()
- : FW_MEventHandler()
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CNumberFilter destructor
- //----------------------------------------------------------------------------------------
- CNumberFilter::~CNumberFilter()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CNumberFilter::DoCharKeyDown
- //----------------------------------------------------------------------------------------
- FW_Handled CNumberFilter::DoCharKeyDown(Environment* ev, const FW_CCharKeyEvent& keyEvent)
- {
- char c = keyEvent.GetChar(ev);
-
- // Allow backspace and arrow keys, characters 0-9 and minus sign
- switch (c)
- {
- case 0x08:
- case 0x1C:
- case 0x1D:
- case 0x1E:
- case 0x1F:
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '-':
- return FW_kNotHandled;
- }
-
- // not a valid character
- FW_Beep();
- return FW_kHandled;
- }
-
-